package org.jeecg.modules.performance.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.modules.performance.entity.PerformanceMonthDepart;
import org.jeecg.modules.performance.mapper.PerformanceMonthDepartMapper;
import org.jeecg.modules.performance.service.IPerformanceMonthDepartService;
import org.jeecg.modules.system.entity.SysDepart;
import org.jeecg.modules.system.entity.SysUserDepart;
import org.jeecg.modules.system.mapper.SysDepartMapper;
import org.jeecg.modules.system.mapper.SysUserDepartMapper;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * @Description: performance
 * @Author: jeecg-boot
 * @Date:   2021-05-18
 * @Version: V1.0
 */
@Service
public class PerformanceMonthDepartServiceImpl extends ServiceImpl<PerformanceMonthDepartMapper, PerformanceMonthDepart> implements IPerformanceMonthDepartService {

    @Autowired
    private  PerformanceMonthDepartMapper performanceMonthDepartMapper;
    @Autowired
    private SysUserDepartMapper sysUserDepartMapper;
    @Autowired
    private  SysDepartMapper sysDepartMapper;


    @Override
    public Page<PerformanceMonthDepart> getList(Page<PerformanceMonthDepart> page, String name, Integer sureFlag) {
        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        QueryWrapper<SysUserDepart>queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id",user.getId());

        SysUserDepart sysUserDepart = sysUserDepartMapper.selectOne(queryWrapper);

        QueryWrapper<SysDepart>departQueryWrapper = new QueryWrapper<>();
        departQueryWrapper.eq("id",sysUserDepart.getDepId());

        SysDepart sysDepart = sysDepartMapper.selectOne(departQueryWrapper);
        return page.setRecords(performanceMonthDepartMapper.getList(page,name,sureFlag,sysDepart.getFirstId()));
    }
}
